﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Bass.Tools;
using MySql.Data.MySqlClient;

public partial class admin_item_detail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["adminname"]) == "")
        {
            Response.Write("<script language=javascript>alert('您没有登录');window.parent.document.location.href ='admin_login.aspx'</script>");
        }
        else if (Convert.ToString(Session["adminkind"]) != "product")
        {
            Response.Write("<script language=javascript>alert('您不是产品管理员，无权访问此页！');location='admin_login.aspx'</script>");
        }


        else if (!this.IsPostBack)
        {
            //OleDbConnection Conn = new OleDbConnection();
            //Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("../miumiu.mdb");
            //Conn.Open();

            //取到连接字符串
            string propertiesPath = Server.MapPath("../mysqldb.properties");
            mytools mt = new mytools();
            string ConnString = mt.getMysqlConn(propertiesPath);

            //打开连接
            MySqlConnection myConnection = new MySqlConnection(ConnString);
            myConnection.Open();

            string temp = Request.QueryString["productnum"];
            MySqlDataAdapter da = new MySqlDataAdapter("select * from product_info where productnum='" + Request.QueryString["productnum"] + "'", myConnection);
            DataSet ds = new DataSet();
            da.Fill(ds, "iteminformation");
            DataRowView rowview = ds.Tables["iteminformation"].DefaultView[0];
            productnum.Text = rowview["productnum"].ToString();
            producttitle.Text = rowview["producttitle"].ToString();
            productprice.Text = rowview["productprice"].ToString();
            introduction.Text = rowview["introduction"].ToString();
            introduction2.Text = rowview["introduction2"].ToString();
            introduction3.Text = rowview["introduction3"].ToString();
            introduction4.Text = rowview["introduction4"].ToString();
            introduction5.Text = rowview["introduction5"].ToString();
            introduction6.Text = rowview["introduction6"].ToString();
            introduction7.Text = rowview["introduction7"].ToString();
            introduction8.Text = rowview["introduction8"].ToString();
            introduction9.Text = rowview["introduction9"].ToString();
            introduction10.Text = rowview["introduction10"].ToString();

            producturl.Text = rowview["producturl"].ToString();
            
            abroadornot.Text = rowview["abroadornot"].ToString();
            recommendornot.Text = rowview["recommendornot"].ToString();
            addtime.Text = rowview["addtime"].ToString();
            addadminname.Text = rowview["addadminname"].ToString();
            productkind.Text = rowview["productkind"].ToString();
            productsource.Text = rowview["source"].ToString();

            detail.Text = rowview["detail"].ToString();
            detail2.Text = rowview["detail2"].ToString();
            detail3.Text = rowview["detail3"].ToString();
            detail4.Text = rowview["detail4"].ToString();
            detail5.Text = rowview["detail5"].ToString();

            detailurl.Text = rowview["detailurl"].ToString();
            detailurl2.Text = rowview["detailurl2"].ToString();
            detailurl3.Text = rowview["detailurl3"].ToString();
            detailurl4.Text = rowview["detailurl4"].ToString();
            detailurl5.Text = rowview["detailurl5"].ToString();

            productstatus.Text = rowview["productstatus"].ToString();

            picaddr.Text = rowview["picaddr"].ToString();
            ds.Clear();
            myConnection.Close();
        }
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        //Response.Write("<script language=javascript>window.parent.document.location.href ='item_list.aspx'</script>");
        Response.Write("<script language=javascript>window.parent.main.location.href = 'item_list.aspx';</script>");
        
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        //取到连接字符串
        string propertiesPath = Server.MapPath("../mysqldb.properties");
        mytools mt = new mytools();
        string ConnString = mt.getMysqlConn(propertiesPath);

        //打开连接
        MySqlConnection myConnection = new MySqlConnection(ConnString);
        myConnection.Open();

        string producttitle1 = producttitle.Text.ToString();
        string productprice1 = productprice.Text.ToString();
        string introduction1 = introduction.Text.ToString();
        string introduction2e = introduction2.Text.ToString();
        string introduction3e = introduction3.Text.ToString();
        string introduction4e = introduction4.Text.ToString();
        string introduction5e = introduction5.Text.ToString();
        string introduction6e = introduction6.Text.ToString();
        string introduction7e = introduction7.Text.ToString();
        string introduction8e = introduction8.Text.ToString();
        string introduction9e = introduction9.Text.ToString();
        string introduction10e = introduction10.Text.ToString();
        string producturl1 = producturl.Text.ToString();
        string abroadornot1 = abroadornot.Text.ToString();
        string recommendornot1 = recommendornot.Text.ToString();
        string picaddr1 = picaddr.Text.ToString();
        string detail1 = detail.Text.ToString();
        string detailurle = detailurl.Text.ToString();
        string detail2e = detail2.Text.ToString();
        string detailurl2e = detailurl2.Text.ToString();
        string detail3e = detail3.Text.ToString();
        string detailurl3e = detailurl3.Text.ToString();
        string detail4e = detail4.Text.ToString();
        string detailurl4e = detailurl4.Text.ToString();
        string detail5e = detail5.Text.ToString();
        string detailurl5e = detailurl5.Text.ToString();

        MySqlCommand scd = new MySqlCommand("update product_info set producttitle='" + producttitle1 + "',productprice='" + productprice1 + "',introduction='" + introduction1 + "',introduction2='" + introduction2e + "',introduction3='" + introduction3e + "',introduction4='" + introduction4e + "',introduction5='" + introduction5e + "',introduction6='" + introduction6e + "',introduction7='" + introduction7e + "',introduction8='" + introduction8e + "',introduction9='" + introduction9e + "',introduction10='" + introduction10e + "',producturl='" + producturl1 + "',abroadornot='" + abroadornot1 + "',recommendornot='" + recommendornot1 + "',picaddr='" + picaddr1 + "',detail='" + detail1 + "',detailurl='" + detailurle + "',detail2='" + detail2e + "',detailurl2='" + detailurl2e + "',detail3='" + detail3e + "',detailurl3='" + detailurl3e + "',detail4='" + detail4e + "',detailurl4='" + detailurl4e + "',detail5='" + detail5e + "',detailurl5='" + detailurl5e + "' where productnum='" + Request.QueryString["productnum"] + "'", myConnection);
        scd.ExecuteNonQuery();
        Response.Write("<script lanuage=javascript>alert('修改成功');location='item_detail.aspx?productnum=" + Request.QueryString["productnum"] + "'</script>");

        myConnection.Close();
    }

}